package cn.gp.chatclient.ui.component;

import cn.gp.chatclient.utils.ImageUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @ClassName NavigationButton
 * @Description TODO
 * @Author He Guoping
 * @Date 2025/6/17 9:12
 * @Version JDK17
 */
public class NavigationButton extends JButton {
    private boolean selected = false;

    public NavigationButton(String text, String iconPath) {
        super(text);
        setPreferredSize(new Dimension(80, 60));
        setVerticalTextPosition(SwingConstants.BOTTOM);
        setHorizontalTextPosition(SwingConstants.CENTER);
        setBorderPainted(false);
        setFocusPainted(false);
        setContentAreaFilled(false);
        setForeground(Color.WHITE);
        setFont(new Font("微软雅黑", Font.PLAIN, 12));

        // 设置图标
        ImageIcon icon = ImageUtil.getScaledImageIcon(iconPath, 24, 24);
        setIcon(icon);

        // 鼠标悬停效果
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseEntered(MouseEvent e) {
                if (!selected) {
                    setBackground(new Color(50, 54, 62));
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                if (!selected) {
                    setBackground(new Color(40, 44, 52));
                }
            }
        });
    }

    public void setSelected(boolean selected) {
        this.selected = selected;
        if (selected) {
            setBackground(new Color(30, 34, 42));
        } else {
            setBackground(new Color(40, 44, 52));
        }
    }
}
